package cn.jtfadmin.cms.range;

import cn.jtfadmin.cms.domain.entity.CmsEntity;
import cn.jtfadmin.cms.domain.entity.CmsMenuEntity;
import cn.jtfadmin.core.modules.range.DepartRange;
import org.springframework.stereotype.Component;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

/**
 * cms 实体数据范围
 * @author jtf
 * @since 0.0.2
 */
@Component
public class CmsDepartRange implements DepartRange {
    @Override
    public CriteriaBuilder.In<Object> toPredicateIn(Class<?> entityClass, Root root, CriteriaQuery query, CriteriaBuilder criteriaBuilder) {
        if (CmsEntity.class.equals(entityClass)) {
            return criteriaBuilder.in(root.get("sysDepart").get("id"));
        }else if(CmsMenuEntity.class.equals(entityClass)){
            return criteriaBuilder.in(root.get("cms").get("sysDepart").get("id"));
        }
        return null;
    }
}
